None => return vec!(),
Some(deps) => deps,
};
- deps.map(|id| self.get_package(id)).filter(|dep| {
+ let mut ret = deps.map(|id| self.get_package(id)).filter(|dep| {
let pkg_dep = pkg.dependencies().iter().find(|d| {
d.name() == dep.name()
}).unwrap();
}).filter_map(|pkg| {
pkg.targets().iter().find(|&t| self.is_relevant_target(t))
.map(|t| (pkg, t))
- }).collect()
+ }).collect::<Vec<_>>();
+
+ // If this target is a binary, test, example, etc, then it depends on
+ // the library of the same package. The call to `resolve.deps` above
+ // didn't include `pkg` in the return values, so we need to special case
+ // it here and see if we need to push `(pkg, pkg_lib_target)`.
+ if !target.profile().is_custom_build() &&
+ (target.is_bin() || target.is_example()) {
+ let pkg = self.get_package(pkg.package_id());
+ let target = pkg.targets().iter().filter(|t| {
+ t.is_lib() && t.profile().is_compile() &&
+ (t.is_rlib() || t.is_dylib())
+ }).next();
+ if let Some(t) = target {
+ ret.push((pkg, t));
+ }
+ }
+ return ret;
}
/// Gets a package for the given package id.
try!(link_to(cmd, pkg, target, cx, kind));
}
- let targets = package.targets().iter().filter(|target| {
- target.is_lib() && target.profile().is_compile()
- });
-
- if (target.is_bin() || target.is_example()) &&
- !target.profile().is_custom_build() {
- for target in targets.filter(|f| f.is_rlib() || f.is_dylib()) {
- try!(link_to(cmd, package, target, cx, kind));
- }
- }
-
return Ok(());
fn link_to(cmd: &mut CommandPrototype, pkg: &Package, target: &Target,
execs().with_status(0)
.with_stdout(""));
});
+
+test!(rebuild_tests_if_lib_changes {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/lib.rs", "pub fn foo() {}")
+ .file("tests/foo.rs", r#"
+ extern crate foo;
+ #[test]
+ fn test() { foo::foo(); }
+ "#);
+
+ assert_that(p.cargo_process("build"),
+ execs().with_status(0));
+ assert_that(p.cargo("test"),
+ execs().with_status(0));
+
+ File::create(&p.root().join("src/lib.rs")).unwrap();
+
+ assert_that(p.cargo("build"),
+ execs().with_status(0));
+ assert_that(p.cargo("test").arg("-v"),
+ execs().with_status(101));
+});